Two types of data-manipulation:
… but same syntax and in one dataframe.
PS: always an option, do (2) in SAS, Stata, etc. before reading and joining data (previous step).
library(here)
library(sf)
library(tmap)
library(dplyr)
library(readxl)
library(mapview)
# (1) load spatial data
raillines <- st_read(here('data/source/census_1851_raillines/1851EngWalesScotRail_Lines.shp'))
districts_spatial <- st_read(here('data/source/census_1851_districts/1851EngWalesRegistrationDistrict.shp')) %>%
mutate(CEN1 = as.numeric(as.character(CEN1))) # make sure identifiers are the same type
# (2) load and add data-of-interest
districts_data <- read_excel(here('data/census1851_districts_count.xlsx'))
districts <- left_join(districts_spatial, districts_data, by = c('CEN1' = 'district_id'))
districts <- districts %>%
mutate(pct_prof = tertiary_services_professions / total)
mapview(districts, zcol = 'pct_prof')